import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;

@WebServlet(name = "/deletestudent",urlPatterns = "/deletestudent")
public class DeleteStudent extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //获取得到的参数
        String sno = req.getParameter("sno");
        //设置返回值格式
        resp.setContentType("text/html;charset=utf-8");
        int delete = StudentDAO.delete(sno);
        ObjectMapper mapper = new ObjectMapper();
        HashMap map = new HashMap();
        if(delete!=0){
            map.put("code",delete);
        }else{
            map.put("code",0);
        }
        String s = mapper.writeValueAsString(map);
        resp.getWriter().write(s);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
